In case the question means that at least a Latin letter and a digit is always present in the result (that's how I've interpreted anyway) the logic changes.
A quick & dirty approach could be something like the following:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#define AB "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
#define ABLEN ( sizeof(AB) - 1 )
#define ARRSIZ 5
int main( void )
{
srand( time(NULL) );
char arr[ARRSIZ] = {'\0'}; // not a cstring
int nletters = 1 + (rand() % (ARRSIZ-1));
int ndigits = ARRSIZ - nletters;
printf( "nletters: %d, ndigits: %d\n", nletters, ndigits );
int i = 0;
while ( ndigits || nletters ) {
int c = AB[ rand() % ABLEN ];
if ( nletters && isalpha(c) ) {
nletters--;
}
else if ( ndigits && isdigit(c) ) {
ndigits--;
}
else {
continue;
}
arr[i++] = c;
}
printf( "%.5s\n", arr );
return 0;
}
PS. I chose to NOT treat arr as a cstring, since the question seems not to imply such a thing. However, if further manipulation of arr can benefit of cstring-like operations, it should be more useful to define/treat it as a cstring from the beginning.